package cn.edu.scau.cmi.wujiacheng.mutiton;
import java.util.ArrayList;

public class Marshal {
	private static final int N = 10;

	private static ArrayList<Marshal> list = new ArrayList<Marshal>(N);

	private int no;

	private String name; 
	private Marshal(int no) {
		this.no = no;
		System.out.println("-- Create Marshal Object[" + no + "]!");
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	static {
		for (int i = 0; i < N; i++) {
			list.add(new Marshal(i));
		}
	}

	public static Marshal getRandomInstance(String name) {
		for(int i = 0; i < N; i++)
		{
			Marshal mar = list.get(i);
			if (mar.getName() == null) {
				mar.setName(name);
				return mar;
			}
		}
		return null;
	}

	public int getNo() {
		return no;
	}

	public void setNo(int no) {
		this.no = no;
	}
}
